'use strict'
var info = require('./Info')
// info();
var Crawler = require("crawler");

var table = require('./Table')

var c = new Crawler({
    maxConnections: 10,
    callback: function (error, res, done) {
        if (error) {
            console.log(error);
        } else {
            var $ = res.$;

            var list = $('.dw_table .el').toArray();
            list.forEach(element => {
                var job = $(element).find('.t1 a').attr('title');

                var company = $(element).find('.t2 a').text().trim().replace(/[ \n\r]/g, '');

                var place = $(element).find('.t3').text().trim().replace(/[ \n\r]/g, '');;

                var money = $(element).find('.t4').text().trim().replace(/[ \n\r]/g, '');;

                var time = $(element).find('.t5').text().trim().replace(/[ \n\r]/g, '');;

                table.create({ job: job, company:company, place:place, money:money,time:time })
            });
            // $ is Cheerio by default
            //a lean implementation of core jQuery designed specifically for the server

            done();

        }
    }
});

// Queue just one URL, with default callback
for (var index = 1; index <= 3; index++) {
    var URL = 'https://search.51job.com/list/110300,000000,0000,32,9,99,%25E8%25BD%25AF%25E4%25BB%25B6%25E5%25B7%25A5%25E7%25A8%258B%25E5%25B8%2588,2,' + index + '.html?lang=c&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&ord_field=0&dibiaoid=0&line=&welfare=='
    c.queue(URL);
}